<template>
	<view>	
		
		<view v-if="globalLoad">
			
			<block v-if="path.index && path.index.path">
				
				 <!-- #ifndef MP-TOUTIAO -->
				<st-customize-header v-if="showHeader"></st-customize-header>
				<!-- 头部 -->
				<!-- #endif -->
				
				<block v-if="path.index.path === 'stourwebcms_templet_uni_no304_index'">
					<!-- 手机热门线路首页模板 -->
					<temIndex2></temIndex2>
				</block>
				<block v-else-if="path.index.path === 'stourwebcms_templet_uni_no305_index'">
					<!-- 小清新首页模板 -->
					<temIndex3></temIndex3>
				</block>
				<block v-else-if="path.index.path === 'stourwebcms_templet_uni_no306_index'">
					<!-- 手机清爽模板 -->
					<temIndex4></temIndex4>
				</block>
				<block v-else-if="path.index.path === 'stourwebcms_templet_uni_no307_index'">
					<!-- UNI手机综合首页模板 -->
					<temIndex5 :scrollTop="scrollTop"></temIndex5> 
				</block> 
				<block v-else-if="path.index.path === 'stourwebcms_templet_uni_no308_index'">
					<!-- UNI手机单酒店首页模板 -->
					<temIndex6 ref="hotel"></temIndex6> 
				</block>
				<block v-else-if="path.index.path === 'stourwebcms_templet_uni_no309_index'">
					<!-- UNI手机景区首页模板 -->
					<temIndex7 ref="spot" :scrollTop="scrollTop"></temIndex7>
				</block>
				<block v-else-if="path.index.path === 'stourwebcms_templet_uni_no310_index'">
					<!-- UNI手机多酒店首页模板 --> 
					<temIndex8 :destination="destination" :start_date="start_date" :start_date_fill="start_date_fill" :start_week="start_week" :end_date="end_date" :end_date_fill="end_date_fill" :end_week="end_week" :dayNum="dayNum" :scrollTop="scrollTop"></temIndex8>
				</block>
				<block v-else-if="path.index.path === 'stourwebcms_templet_uni_no311_index'">
					<!-- UNI文旅综合首页模板 -->
					<temIndex9 :scrollTop="scrollTop"></temIndex9> 
				</block>
				<block v-else-if="path.index.path === 'stourwebcms_templet_uni_no312_index'">
					<!-- 游轮首页模板 -->
					<temIndex10 :scrollTop="scrollTop" :scheduleDate="scheduleDate" :startDest="startDest" :endDest="endDest" @changeCity="changeCity"></temIndex10> 
				</block>
				
				<block v-else>
					<temIndex :scrollTop="scrollTop"></temIndex>
				</block>
			</block>
			<block v-else>
				
				<!-- #ifndef MP-TOUTIAO -->
				<st-customize-header v-if="showHeader"></st-customize-header>
				<!-- 头部 -->
				<!-- #endif -->
				
				<temIndex :scrollTop="scrollTop"></temIndex>
				
			</block>
		
		<!-- #ifdef MP-WEIXIN -->
		<st-weixin-privacy :showPrivacy="showPrivacy" @confirm="shutUp" @disagree="shutUp"></st-weixin-privacy>
		<!-- 用户隐私授权弹窗 -->
		<!-- #endif -->
			
		</view>
	</view>
</template>

<script>
	import stCustomizeHeader from "@/components/st-customize-header.vue";
	import temIndex from "@/components/templates/templates_global_home.vue";
	import temIndex2 from "@/components/templates/stourwebcms_templet_uni_no304_index.vue";
	import temIndex3 from "@/components/templates/stourwebcms_templet_uni_no305_index.vue";
	import temIndex4 from "@/components/templates/stourwebcms_templet_uni_no306_index.vue";
	import temIndex5 from "@/components/templates/stourwebcms_templet_uni_no307_index.vue";
	import temIndex6 from "@/components/templates/stourwebcms_templet_uni_no308_index.vue";
	import temIndex7 from "@/components/templates/stourwebcms_templet_uni_no309_index.vue";
	import temIndex8 from "@/components/templates/stourwebcms_templet_uni_no310_index.vue";
	import temIndex9 from "@/components/templates/stourwebcms_templet_uni_no311_index.vue";
	import temIndex10 from "@/components/templates/stourwebcms_templet_uni_no312_index.vue";
	import stWeixinPrivacy from "@/components/st-weixin-privacy.vue";
	import { get_date_format } from '@/utils/utils.js'
	export default {
		components: {
			stCustomizeHeader,
			temIndex,
			temIndex2,
			temIndex3,
			temIndex4,
			temIndex5,
			temIndex6,
			temIndex7,
			temIndex8,
			temIndex9,
			temIndex10,
			stWeixinPrivacy
		},
		
		data() {
			return {
				globalLoad: false,
				scrollTop: 0,
				path: '',
				temp: [],
				start_date: '',
				end_date: '',
				dayNum: 1,
				isUpdate: false,
				reload: false,
				shareData:{},
				topHeight: 0,
				statusHeight: 0,
				headerHeight: 0,
				cfgIndextitle:"首页",
				destination: {
					pinyin:'',
					kindname:''
				},
				start_date_fill:'',
				start_week:'今天',
				end_date_fill:'',
				end_week:'明天',
				showHeader: true,
				
				// 游轮模板数据
				scheduleDate: '',
				startDest: { // 出发地
					destid: '',
					cityname: '',
				},
				endDest: { // 到达地
					destid: '',
					cityname: '',
				},
				// #ifdef MP-WEIXIN
				showPrivacy: false, //是否展示用户隐私弹窗
				// #endif 
			}
		},
		onReady() {
			let cfg_home_page_title = uni.getStorageSync('cfg_home_page_title');
			this.cfgIndextitle = cfg_home_page_title?cfg_home_page_title:this.cfgIndextitle;
		},
		onLoad(options) {
			this.getTempInfo();
			// 请求参数统一管理
			options = this.$optionsManager(options)
			
			this.scheduleDate = get_date_format(new Date())
			
		},
		onShow() {
			this.hotelInit()
			
			this.$nextTick(() => {
				if(this.$refs.home){
					this.$refs.home.dest = this.destination
				}           
			});
			
			// 游轮选择城市
			if(this.reload){
				this.reload = false
			}
			
			// #ifdef MP-WEIXIN
			this.getPrivacy();
			// #endif
		
			// #ifdef H5
			// 页面分享
			this.$share();
			// #endif
			
			// #ifdef MP-ALIPAY || MP-BAIDU || MP-WEIXIN || MP-TOUTIAO
			this.sharePage();
			// #endif
		},
		
		watch: {
			destination(n, o){
				
			}
		},
		
		onReachBottom() {
			if(this.path.index && this.path.index.path === 'stourwebcms_templet_uni_no309_index'){
				this.$refs.spot.getRecommendList();
			}
		},
		
		// #ifdef MP-ALIPAY || MP-BAIDU || MP-WEIXIN || MP-TOUTIAO
		onShareAppMessage(res) { //右上角分享 微信小程序、百度小程序、字节跳动小程序、支付宝小程序
			if (this.shareData) {
				let sdata = this.shareData
				delete sdata.imageUrl;
				return sdata;
			}
		},
		onShareTimeline() { // 分享朋友圈
			if (this.shareData) {
				return this.shareData;
			}
		},
		
		// #endif
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		methods: {
			
			// #ifdef MP-ALIPAY || MP-BAIDU || MP-WEIXIN || MP-TOUTIAO
			//分享页面
			async sharePage() {
				let shareInfo = {};
				let shareData = await this.$mpShare(shareInfo);
				if (shareData) {
					this.shareData = shareData;
				}
			},
			// #endif
			
			// #ifdef MP-WEIXIN
			getPrivacy() {
				if (uni.getPrivacySetting) {
					uni.getPrivacySetting({
						success: res => {
							if (res.needAuthorization) {
								this.showPrivacy = true;
							} else {
								this.showPrivacy = false;
							}
						},
						fail: () => {},
						complete: () => {},
					})
				}
			},
			
			//关闭'用户隐私授权弹窗'
			shutUp() {
				this.showPrivacy = false;
			},
			// #endif
			
			async getTempInfo(){
				let infoRes,
				params = {
					method: "api/v2/system/get_template_no"
				}
				uni.showLoading({
					title: '加载中...'
				})
				infoRes = await this.$http(params);
				if(infoRes.status){
					uni.hideLoading();
					this.globalLoad = true;
					
					this.path = infoRes.data.path;
					this.temp = infoRes.data.tem;
					let index = infoRes.data.path.index;
			
					if(index && (index.path === 'stourwebcms_templet_uni_no309_index' || index.path === 'stourwebcms_templet_uni_no311_index' || index.path === 'stourwebcms_templet_uni_no312_index')){
						this.showHeader = false;
					}
					if(index && index.path === 'stourwebcms_templet_uni_no310_index'){
						this.showHeader = false;
						this.start_date = get_date_format(Date.now());
						this.start_date_fill = get_date_format(Date.now()).slice(5).replace(/-/g, '月') + '日';
						this.end_date = get_date_format(Date.now() + 60*60*24*1000);
						this.end_date_fill = get_date_format(Date.now() + 60*60*24*1000).slice(5).replace(/-/g, '月') + '日'
					}
				}
			},
			
			hotelInit(){
				if(this.$refs.hotel){
					this.$refs.hotel.hasLogin = this.$store.state.hasLogin;
					if(this.isUpdate){ // 登录后重新请求数据
						this.isUpdate = false;
						this.$refs.hotel.getSuitList();
					}
					if(this.reload){ // 单酒店模板日历房型筛选
						this.reload = false;
						this.$refs.hotel.start_date = this.start_date.replace(/\//g, '-');
						this.$refs.hotel.end_date = this.end_date.replace(/\//g, '-');
						this.$refs.hotel.dayNum = this.dayNum;
						this.$refs.hotel.getSuitList();
					}
				}
			},
			
			// 游轮切换城市
			changeCity(){
				let sdest = {
						...this.startDest
					},
					edest = {
						...this.endDest
					}
					
				this.startDest = {
					...edest
				}
				this.endDest = {
					...sdest
				}
			}
		}
	}
</script>